// AJAX
var xmlhttp = new getXMLObject();

// OPERATIONS
var USER_LOGIN = "user_login";
var USER_LOGOUT = "user_logout";

function login() {
	if (xmlhttp) {
		xmlhttp.open("POST", "setup", false);
		xmlhttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded;");
		xmlhttp.send("operation=" + USER_LOGIN);
	}

	handleLogin();
}

function logout() {
	if (xmlhttp) {
		xmlhttp.open("POST", "setup", false);
		xmlhttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded;");
		xmlhttp.send("operation=" + USER_LOGOUT);
	}
	handleLogout();
}

function getXMLObject() {
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
		} catch (e2) {
			xmlHttp = false
		}
	}
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}

function handleLogin() {
	if (xmlhttp.status == 200) {
		var url = xmlhttp.responseXML.getElementsByTagName("url")[0];
		window.location = url.firstChild.nodeValue;
	}
}

function handleLogout() {
	if (xmlhttp.status == 200) {
		var url = xmlhttp.responseXML.getElementsByTagName("url")[0];
		window.location = url.firstChild.nodeValue;
	}
}
